App({
  onLaunch: function() {
    wx.hideTabBar()
    // 处理金币
    var gold = wx.getStorageSync('baibao_userinfo_gold')
    if (gold) {
      this.globalData.gold = gold
    } else {
      gold = 0
    }
    wx.setStorageSync('baibao_userinfo_gold', gold)

    // 处理历史记录
    var list = wx.getStorageSync('baibao_game_history')
    if (!list) {
      wx.setStorageSync('baibao_game_history', [])
    }

    // 处理每日任务
    var now = new Date()
    var today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate()
    var yesterday = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + (now.getDate() - 1)
    var taskList = wx.getStorageSync('baibao_task_list_' + today)
    if (!taskList) {
      taskList = {
        'sign': 0,
        'one_game': 0,
        'share': 0,
        'five_game': 0
      }
    }
    wx.removeStorageSync('baibao_task_list_' + yesterday)
    wx.setStorageSync('baibao_task_list_' + today, taskList)
    this.globalData.taskList = taskList
  },

  editTabbar: function() {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
  },

  globalData: {
    gold: 0,
    version: '1.0.4',
    taskList: [],
    url: 'https://xcx.nanxuncn.com/api/hezi/hezi/',
    appid: "wxa9002f27f3ed1519",
    isUserSystemIos: false, // 用户是否是ios系统
    systemInfo: null, //客户端设备信息
    userInfo: null,
    tabBar: {
      "color": "#363636",
      "selectedColor": "#58b5f0",
      "backgroundColor": "#fff",
      "position": "bottom",
      "list": [{
          "pagePath": "/pages/index/index",
          "iconPath": "/images/index.png",
          "selectedIconPath": "/images/index_act.png",
          "text": "首页"
        },
        {
          "pagePath": "/pages/find/find",
          "iconPath": "/images/find.png",
          "selectedIconPath": "/images/find_act.png",
          "text": "发现"
        },
        {
          "pagePath": "/pages/mine/mine",
          "iconPath": "/images/mine.png",
          "selectedIconPath": "/images/mine_act.png",
          "text": "我的"
        }
      ]
    }

  }

})